<template>
    <div>
        <h1>病房列表</h1>
        科室:
        <select v-model="cs.kid">
            <option value="0">请选择科室</option>
            <option v-for="d in xl" :value="d.kid">{{ d.kname }}</option>
        </select>
        <input type="text" placeholder="病房名称" v-model="cs.name">
        <input type="button" value="查询" class="btn btn-success" @click="show">
        <table class="table">
            <thead>
                <tr>
                    <td>病房名称</td>
                    <td>病房号</td>
                    <td>所属科室</td>
                    <td>病房总数量</td>
                    <td>已满/未满</td>
                    <td>状态</td>
                    <td>空闲床数量</td>
                    <td>创建日期</td>
                    <td>操作</td>
                </tr>
            </thead>
            <tbody>
                <tr v-for="d in data">
                    <td>{{ d.bname }}</td>
                    <td>{{ d.bnum }}</td>
                    <td>{{ d.kname }}</td>
                    <td>{{ d.znum }}</td>
                    <td>{{ d.mstart==true?'已满':'未满' }}</td>
                    <td>{{ d.start?'启用':'维修' }}</td>
                    <td>{{ d.knum }}</td>
                    <td>{{ moment(d.createTime).format("yyyy-MM-DD hh:mm:ss") }}</td>
                    <td>
                        <input type="button" :value="d.start?'维修':'启用'" class="btn btn-success" @click="upd(d.bid)">
                    </td>
                </tr>
            </tbody>
        </table>
        <a href="/bfadd">病房添加</a>
        <br>
        <a href="/ksadd">科室添加</a>
    </div>
</template>

<script setup lang="ts">
import {ref,onMounted} from 'vue'
import axios from 'axios';
import moment from 'moment';
const data=ref([
    {
    "bid": 1,
    "bnum": "1001",
    "bname": "内科病房",
    "znum": 15,
    "start": true,
    "knum": 3,
    "createTime": "2025-05-19T09:33:34.9370241",
    "mstart": false,
    "kid": 1,
    "kname": "内科"
  }
])
//文档就续
onMounted(()=>{
    bang()
    show()
})
//参数
const cs=ref({
    kid:0,
    name:''
})
//显示
const show=()=>{
    axios.get("/api/Bf/GetBf",{params:cs.value}).then(res=>{
        data.value=res.data
    })
}
//绑定
const xl=ref({})
const bang=()=>{
    axios.get("/api/Ks/GetKsXl").then(res=>{
        xl.value=res.data
    })
}
//修改状态
const upd=(mid:any)=>{
    axios.get("/api/Bf/UpdStart",{params:{id:mid}}).then(res=>{
        if(res.data>0){
            alert('修改成功');
            show()
        }
        else{
            alert('修改失败');
            return;
        }
    })
}
</script>

<style scoped>

</style>